package com.rongji.dfish.demo.pub.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.rongji.dfish.base.Utils;
import com.rongji.dfish.demo.constant.DemoConstants;
import com.rongji.dfish.demo.entity.PubLoginUser;
import com.rongji.dfish.framework.service.BaseService;

/**
 * 
 * @author DFish Team 
 *
 */
@Service
public class UserService extends BaseService<PubLoginUser, String> {
	
	public PubLoginUser getUserByLoginName(String loginName) {
		if (Utils.isEmpty(loginName)) {
			return null;
		}
		List<PubLoginUser> result = (List<PubLoginUser>) getPubCommonDAO().getQueryList("FROM PubLoginUser t WHERE t.loginName=?", loginName);
		if (Utils.notEmpty(result)) {
			return result.get(0);
		}
		return null;
	}
	
//	public String regUser(String userName,String loginName,String password) {
//		if (Utils.isEmpty(userName)||Utils.isEmpty(loginName)||Utils.isEmpty(password)) {
//			return "";
//		}
//		PubLoginUser loginUser=new PubLoginUser();
//		loginUser.setLoginName(loginName);
//		loginUser.setUserId(IdGenerator.getTimeSortedId());
//		loginUser.setUserName(userName);
//		loginUser.setUserPwd(password);
//		getPubCommonDAO().save(loginUser);
//		return loginUser.getUserId();
//	}
	
	public static PubLoginUser getGuestUser() {
		PubLoginUser loginUser = new PubLoginUser();
		loginUser.setUserId(DemoConstants.USER_GUEST);
		loginUser.setLoginName(DemoConstants.USER_GUEST);
		loginUser.setUserName("游客");
		return loginUser;
	}
	
	public static PubLoginUser getAdminUser() {
		PubLoginUser loginUser = new PubLoginUser();
		loginUser.setUserId(DemoConstants.USER_ADMIN);
		loginUser.setLoginName(DemoConstants.USER_ADMIN);
		loginUser.setUserName("管理员");
		return loginUser;
	}
	
}
